﻿<div class="@ClassName">
    @foreach (var m in Message.Reverse())
    {
        <div class="log-item">@m</div>
    }
</div>

@code {
    protected System.Collections.Concurrent.ConcurrentQueue<string> Message { get; set; } = new System.Collections.Concurrent.ConcurrentQueue<string>();

    /// <summary>
    /// 获得 按钮样式集合
    /// </summary>
    /// <returns></returns>
    protected string? ClassName => CssBuilder.Default("card-log")
        .AddClassFromAttributes(AdditionalAttributes)
        .AddClass(Class)
        .Build();

    protected string Class { get; set; } = "collapse";

    /// <summary>
    /// 获得/设置 用户自定义属性
    /// </summary>
    [Parameter(CaptureUnmatchedValues = true)]
    public IDictionary<string, object>? AdditionalAttributes { get; set; }

    public void Log(string message)
    {
        Message.Enqueue($"{DateTimeOffset.Now}: {message}");
        Class = "";
        if (Message.Count > 3) Message.TryDequeue(out var s);
        StateHasChanged();
    }
}
